        TITL DAI FIRMWARE 2EBF4-2EDF5  V1.0  Rev.1
        ORG   :EBF4
*
*
*
*   =====================
*** SCREEN EDITOR PACKAGE ***
*   =====================
*
*
*********************
* INITIALISE EDITOR *
*********************
*
* Sets up a mode 0 screen, clears 00A8-00AD,00AF.
* Prints text from 00A2 onwards; cursor at top left.
*
* Exit: HL: Cursor position (top left).
*       AF corrupted. BCDE preserved.
*
EINIT   MVI   A,:FF     Init mode 0
        CALL  :E3D9     Change to mode 0
        MVI   A,:0C
        CALL  :E102     Clear screen
        LXI   H,:0000   )
        SHLD  :00A9     )
        SHLD  :00AC     )
        MOV   A,H       ) Clear edit pointers
        STA   :00A8     )
        STA   :00AB     )
        STA   :00AF     )
        LHLD  :0072     Get cursor pos addr
        CALL  :E36B     Delete cursor
        CALL  :EF3A     Print full screen from
 REM start of edit buffer
        CALL  :E330     Put cursor on screen
        RET
*
*************
* OBEY EDIT *
*************
*
* A given character is inserted in the buffer,
* except:  #08  deletes a character
*          #10  moves cursor up
*          #11  moves cursor down
*          #12  moves cursor left
*          #13  moves cursor right
*          #14  moves window up
*          #15  moves window down
*          #16  moves window left
*          #17  moves window right
*
* Entry: A:    Character given.
* Exit:  CY=1: If done.
*        CY=0: Not done.
*        ABCDEHL + rest of F preserved.
*
EOBEY   CPI   :08
        JZ    :EFCC     Delete character
        CPI   :10
        JC    :EF4B     Insert character
        JZ    :ED88     Cursor up
        CPI   :12
        JC    :EDAB     Cursor down
        JZ    :EDD3     Cursor left
        CPI   :14
        JC    :EDF6     Cursor right
        JZ    :EC4B     Window up
        CPI   :16
        JC    :ECB3     Window down
        JZ    :ED50     Window left
        CPI   :17
        JZ    :ECF8     Window right
        JMP   :EF4B     Insert character
*
*************
* WINDOW UP *
*************
*
* Moves window up one line.
*
* Exit: All registers preserved.
*       CY=0: Window unchanged.
*       CY=1: Window changed.
*
EWUP    PUSH  D
        PUSH  H
        PUSH  PSW
        LHLD  :00A9     Get offset of top of window
        MOV   A,H
        ORA   L
        JZ    :ECDA     Window unchanged if
 REM offset = 0; CY=0
        XRA   A
        STA   :00AF     Clear cursor pos in buffer
        LDA   :00AC     Get Y-offset cursor in
 REM in document
        SUB   L         Minus offset top of window
        CPI   :17       Nr of lines in window -1
        CZ    :ED88     Cursor up if at
 REM bottom of window
        LHLD  :0072     Get cursor pos addr
        PUSH  H
        CALL  :E36B     Delete cursor
        CALL  :EC74     Move window, correct pntrs
        POP   H
L2E172  LXI   D,:FF7A   Length one line
        JMP   :ECD5     Put cursor on next line,
 REM quit with CY=1
*
* SCROLL EDIT DISPLAY DOWN ONE LINE:
*
* Exit: BC preserved. AFDEHL corrupted.
*
L2E173  PUSH  B
        LXI   B,:0086   Length one screen line
        CALL  :EC86     Move window up in text
 REM 1 line
        PUSH  D
        LHLD  :00A9     Get offset of top of window
        DCX   H         -1
        SHLD  :00A9     And preserve it
        JMP   :ECEF     Print new line of text at
 REM window bottom
*
***********************
* MOVE WINDOW IN TEXT *
***********************
*
* Moves window up or left.
*
* Entry: BC: Offset (#86 for 1 line, #02 for
*            1 position).
* Exit:  All registers corrupted.
*
L2E174  LHLD  :008C     Get addr after end char area
        MOV   D,H       ) in DE
        MOV   E,L       )
        DAD   B         Add offset
        XCHG            HL: end char area;
 REM DE: end char area + offset
* Move full screen:
 REM
L2E175  LXI   B,:0006   3 not used locations
 REM at line end
        DAD   B         )
        XCHG            ) Add it to both HL and DE
        DAD   B         ) and exchange DE and HL
        XCHG            )
        MVI   B,:3C     60 char/line visible
 REM
* Move one line:
 REM
L2E176  INX   H
        INX   H         New destination pntr
        INX   D
        INX   D         New origin pntr
        LDAX  D         Get one char
        MOV   M,A       Move it to new screen loc
        DCR   B         char count -1
        JNZ   :EC96     Next char if not ready
*
        LXI   B,:0008   4 not-useable pos at line
 REM boundary
        DAD   B         HL pnts to end previous line
 REM (destination)
        PUSH  H
        LHLD  :008A     Get addr start char area
        XCHG            in DE
        DAD   B         Update origin too
        CALL  :E6FB     Compare HL-DE
        XCHG            New origin in DE
        POP   H         Destination in HL
        JC    :EC8D     Evt another line
        RET
*
***************
* WINDOW DOWN *
***************
*
* Moves window down one line.
*
* Exit: ABCDEHL preserved.
*       CY=0: Window unchanged.
*       CY=1: Window changed.
*
EWDN    PUSH  D
        PUSH  H
        PUSH  PSW
        LHLD  :00AC     Get Y-offset cursor in
 REM document
        LDA   :00A9     Get offset of top of window
        CMP   L         Cursor at top of screen ?
        CZ    :EDAB     Then cursor down
        JNC   :ECDA     Quit with CY=0 if
 REM window unchanged
        XRA   A
        STA   :00AF     Clear cursor pos in buffer
        LHLD  :0072     Get cursor pos addr
        PUSH  H
        CALL  :E36B     Delete cursor
        CALL  :ECDF     Scroll edit display up
 REM one line
        POP   H
L2E177  LXI   D,:0086   Length one screen line
L2E178  DAD   D         One line further
L2E179  CALL  :E330     Put new cursor on screen
        STC             Exit CY=1 if cursor moved
L2E180  POP   H
        MOV   A,H
        POP   H
        POP   D
        RET
*
* SCROLL EDIT DISPLAY UP ONE LINE:
*
* Exit: BC preserved. AFDEHL corrupted.
*
L2E181  PUSH  B
        CALL  :E1CB     Scroll window up 1 line
        PUSH  H
        LHLD  :00A9     Get offset of top of window
        INX   H         +1
        SHLD  :00A9     Preserve it
        LXI   D,:0017   Nr of lines for window
        DAD   D         HL pnts to new line at
 REM window bottom
L2E182  CALL  :EE1C     Skip lines
        POP   D
        CALL  :EEC0     Print new line of text
        POP   B
        RET
*
****************
* WINDOW RIGHT *
****************
*
* Moves window right one position.
*
* Exit: ABCDEHL preserved.
*       CY=0: Window unchanged.
*       CY=1: Window changed.
*
EWRT    PUSH  D
        PUSH  H
        PUSH  PSW
        LDA   :00A8     Get offset of left side
 REM of window
        CPI   :C4       256-60 ?
        JZ    :ECDA     Abort if window at right end
 REM of text
        MOV   L,A       Offset in L
        LDA   :00AB     Get X-offset cursor in
 REM document
        CMP   L         Cursor at left side of
 REM window ?
        CZ    :EDF6     Then move cursor right
        LHLD  :0072     Get cursor pos addr
        PUSH  H
        CALL  :E36B     Delete cursor
        CALL  :ED1B     Scroll display left 1 pos
        POP   H
L2E184  INX   H
        INX   H
        JMP   :ECD6     Put cursor on screen;
 REM quit with CY=1
*
* SCROLL EDIT DISPAY LEFT ONE POSITION:
*
* Exit: BC preserved, AFDEHL corrupted.
*
L2E185  PUSH  B
        LXI   B,:FFFE   -2
        CALL  :E1CE     Scroll window
        LDA   :00A8     Get offset of left side
 REM of window
        INR   A         +1
        STA   :00A8     Preserve it
        ADI   :3B       +60 (offset right side
 REM of window)
        LXI   D,:FF82   -7E
L2E186  MOV   B,A       Offset right side of
 REM window in B
        MVI   C,:18     Nr of lines in window
        LHLD  :008A     Get pntr to start char area
        DAD   D         Pos 60th char on screen
        XCHG            in DE
        LHLD  :00A9     Get offset of top of window
        CALL  :EE1C     Skip lines
 REM
* Put newly visible 60th character on screen:
 REM
L2E187  CALL  :EE7B     Skip to Bth pos on line
        STAX  D         Next visible char in window
        CALL  :EE38     Next line
        PUSH  H
        LXI   H,:FF7A   -86 (length one line)
        DAD   D         Pnts to 60th char on
 REM next line
        XCHG
        POP   H
        DCR   C         Update line count
L2E188  JNZ   :ED3C     Scroll next line if not
 REM ready
        POP   B
        RET
*
***************
* WINDOW LEFT *
***************
*
* Moves window left one position.
*
* Exit: ABCDEHL preserved.
*       CY=0: Window unchanged.
*       CY=1: Window changed.
*
EWLF    PUSH  D
        PUSH  H
        PUSH  PSW
        LDA   :00A8     Get offset of left side
 REM of window
        ORA   A
        JZ    :ECDA     Abort if offset = 0
        MOV   L,A       Offset in L
        LDA   :00AB     Get X-offset of cursor
 REM in document
        SUB   L
        CPI   :3B       Cursor at right side of
 REM window ?
        CZ    :EDD3     Then cursor left
        LHLD  :0072     Get cursor pos addr
        PUSH  H
        CALL  :E36B     Delete cursor
        CALL  :ED74     Move window, correct pntrs
        POP   H
L2E189  DCX   H
        DCX   H         New cursor pos
        JMP   :ECD6     Put cursor on screen;
 REM quit with CY=1
*
* SCROLL EDIT DISPLAY RIGHT ONE POSITION:
*
* Exit: BC preserved; AFDEHL corrupted.
*
L2E190  PUSH  B
        LXI   B,:0002
        CALL  :EC86     Move window in text
        LDA   :00A8     Get offset of left side
 REM of window
        DCR   A         -1
        STA   :00A8     Preserve it
        LXI   D,:FFF8   Gives in ED2E 1st pos
 REM on 1st screen line
        JMP   :ED2E     Scroll display left
*
*************
* CURSOR UP *
*************
*
* Moves cursor up one position.
*
* Exit: ABCDEHL preserved.
*       CY=0: Cursor not moved.
*       CY=1: Cursor moved.
*
ECUP    PUSH  D
        PUSH  H
        PUSH  PSW
        LHLD  :00AC     Get Y-offset cursor in
 REM document
        MOV   A,H
        ORA   L
        JZ    :ECDA     Quit if cursor at top
 REM left; CY=0
        XRA   A
        STA   :00AF     Clear cursor pos in buffer
        LDA   :00A9     Get offset of top of window
        CMP   L         Cursor at top of window ?
        CZ    :EC4B     Then window up
        DCX   H
        SHLD  :00AC     Store Y-offset cursor in
 REM document
        LHLD  :0072     Get cursor pos addr
        CALL  :E36B     Delete cursor
        JMP   :ECD2     Put cursor on new pos;
 REM quit with CY=1
*
***************
* CURSOR DOWN *
***************
*
* Moves cursor down one position.
*
* Exit: ABCDEHL preserved.
*       CY=0: Cursor not moved.
*       CY=1: Cursor moved.
*
ECDN    PUSH  D
        PUSH  H
        PUSH  PSW
        LHLD  :00AC     Get Y-offset cursor in
 REM in document
        INX   H         +1
        PUSH  H         Preserve it
        CALL  :EE1C     Skip lines
        POP   H
        JNC   :ECDA     No move if cursor at last
 REM line of text; CY=0
        XRA   A
        STA   :00AF     Clear cursor pos in buffer
        LDA   :00A9     Get offset of top of window
        ADI   :18       24 lines in window
        CMP   L         Cursor at window bottom ?
        CZ    :ECB3     Then window down
        SHLD  :00AC     Store Y-offset cursor in
 REM document
        LHLD  :0072     Get cursor pos addr
        CALL  :E36B     Delete cursor
        JMP   :EC6E     Put cursor on new pos;
 REM quit with CY=1
*
***************
* CURSOR LEFT *
***************
*
* Moves cursor left one position.
*
* Exit: ABCDEHL preserved.
*       CY=0: Cursor not moved.
*       CY=1: Cursor moved.
*
ECLF    PUSH  D
        PUSH  H
        PUSH  PSW
        LDA   :00A8     Get offset of left side
 REM of window
        MOV   L,A       in L
        LDA   :00AB     Get X-offset cursor in
 REM document
        ORA   A
        JZ    :ECDA     Abort if X-offset = 0
        CMP   L         Cursor at left side of
 REM window ?
        CZ    :ED50     Then window left
        DCR   A         X-offset -1
        STA   :00AB     Preserve it
        XRA   A
        STA   :00AF     Clear cursor pos in buffer
        LHLD  :0072     Get cursor pos addr
        CALL  :E36B     Delete cursor
        JMP   :ED16     Put cursor on new pos;
 REM quit with CY=1
*
*
*
        END
